home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Tools 4
/
Amiga Tools 4.iso
/
tools
/
protect-your-privacy
/
p.g.p.
/
pgpamiga
/
contrib
/
ced
/
encryptpgp.ced
< prev
next >
Wrap
Text File
|
1996-02-26
|
7KB
|
250 lines
/*******************************************************************/
/* */
/* EncryptPGP.ced - ARexx macro for use with Cygnus Editor and PGP */
/* */
/* Mark a block of text you want to be encrypted using PGP, then */
/* run this macro to encrypt it wit someone's public key. It works */
/* similar to builtin rot13 command. (Only MUCH slower). */
/* This macro was tested to work with Cygnus Editor 2.0 to 3.5. */
/* */
/* This code is in Public Domain under GNU General Public License */
/* */
/* author: Janusz A. Urbanowicz <alex@vm.cc.uni,torun.pl> */
/* */
/* See CEDPGP.guide for more info */
/* */
/*******************************************************************/
/*
* $VER: EncryptPGP.ced 1.3 (30.10.1994)
*/
/* This macro uses PGPUSER environmental variable to determine */
/* which private key should be used to sign the text. If there is no */
/* PGPUSER variable it uses the default key to sign (if needed) */
Trace Off
Options Results
lf = '0A'X
tempfile = 'T:ced$pgp.tmp'
cmdn = '-ea'
cmdf = '<'||tempfile||' -o '||tempfile||'.asc -fea'
pgpt = 0 /* pgp 'type' 0 = 2.3a, 1 = 2.3a.?, 2 = 2.6<ui> */
scratch = 0
ID = ''
scrname = 'CygnusEdScreen'
scrnum = 1
portname = 'rexx_ced'
portnum = 0
/* main() */
status portnumber
portnum = result
if (portnum ~= 0)&(portnum ~== 'RESULT') Then
Do
scrnum = scrnum + portnum
portname = portname||portnum
End
scrname = scrname||scrnum
Call Close 'STDOUT' /* Thanx for that goes to Rick Younie*/
Call Close 'STDIN'
Call Open 'STDOUT','CON:16/24/620/130/PGPAmiga Output/CLOSE/WAIT/SCREEN'||scrname
Call Pragma '*','STDOUT'
Call Open 'STDIN','*'
Call checkf
pgpt = result
If pgpt > 0 Then
Do
cmd = cmdf
cmdline = ''
End
Else
Do
cmd = cmdn
cmdline = tempfile||' '
End
Address Value portname
getstring '" " "Please enter recipient`s userid:"'
ID = result
ID = Strip(ID,'B')
Address Command
'GetEnv >PIPE:PGPUSER PGPUSER'
If rc = 0 Then
Do
If ~Open('user','PIPE:PGPUSER','R') Then
Do
Address value portname
Okay1 "Problem while opening PGPUSER environmental variable"||lf||,
"Fatal error, macro execution aborted."
Call quit
End
Else
Do
userid = ReadLN('user')
If ~Close('user') Then Nop
cmdline = cmdline||ID||' -u '||'"'||userid||'"'
End
End
Else cmdline = cmdline||ID
Address Value portname
If pgpt = 1 Then /* is PGP26_IMPERSONATE option avaliable ? */
Do
okay2 "Do you want the encrypted packet to be"||lf,
"in PGP 2.6 format ?"
If result = 1 Then
Do
okay1 "WARNING: Packet created with this"||lf,
||"option set cannot be processed"||lf,
||"using 'standard' PGP 2.3a."||lf||lf,
||"You SHOULD NOT use this option"
okay2 "Are you sure you want to use"||lf,
||"this option ?"
If result = 1 Then cmdline = cmdline||' +PGP26_IMPERSONATE=on'
End
End
Else cmdline = cmdline||' +batchmode=on'
okay2 "Do you want to sign the text with"||lf||" your private key ??"
If result = 1 Then
Do
If cmd = cmdn Then Call ask
cmd = cmd||'st '
End
Else cmd = cmd||'t '
cmdline = cmd||cmdline
cut block
If result = 1 Then Call encrypt
Else
Do
okay2 "No area selected."||lf||"Encrypt whole file ?"
If result = 1 Then
Do
'beg of file'
'mark block'
'end of file'
'cut block'
Call encrypt
End
End
Call quit
encrypt:
Do
menu 0 6 0 tempfile /* save block to file */
Address Command
'PGP '||cmdline
If ~Exists(tempfile||'.asc') Then Call wrongpass
Else
Do
/* We check if the output file length is 0 what happens if PGP was in -f mode and passphrase was wrong */
If Open('outf',tempfile||'.asc','R') Then
Do
If Seek('outf',100,'Begin') = 0 Then Call wrongpass
Else
Do
Address value portname
include file tempfile||'.asc'
status 21
End
End
End
End
Return
wrongpass:
Address value portname
undo
okay1 "Wrong passphrase !"
quit:
Address Command
If Exists(tempfile||'.info') Then 'Delete '||tempfile||'.info QUIET'
If Exists(tempfile||'.asc') Then 'Delete '||tempfile||'.asc QUIET'
If Exists(tempfile) Then 'Delete '||tempfile||' QUIET'
If scratch == 1 Then 'Delete env:PGPPASS QUIET'
If ~Close('STDOUT') Then Nop
Exit 0
ask: Procedure Expose scratch lf portname
Address Command
'GetEnv >NIL: PGPPASS'
If rc ~= 0 Then
Do
Address value portname
okay2 "Your passphrase is not set in PGPPASS variable."||lf||,
"It must be set temporarily for running PGP".||lf||,
"Should it be deleted (for higher security) after use ??"
If result = 1 then scratch = 1
else scratch = 0
okay1 'WARNING: Your passphrase will be visible when you type it in.'
getstring "' ' 'Please enter passphrase.'"
pgppass = result
pgppass = Strip(pgppass,'T')
Address Command
'SetEnv PGPPASS '||'"'||pgppass||'"'
End
Return
checkf: Procedure
Address Command
Call getpath
path = result
If path = "" Then Return 0
Else
Do
'Version >PIPE:PGPVERSION '||path
If Open('pvers','PIPE:PGPVERSION','R') Then
Do
verstring = ReadLN('pvers')
If Close('pvers') Then Nop
End
Parse Var verstring . version
Select
When version = '2.6ui' Then Return 2
When version = '2.3a.5' Then Return 1
When version = '2.3a.4' Then Return 1
When version = '2.3a.3' Then Return 1
Otherwise Return 0
End
End
getpath: procedure
'Which >PIPE:PGPPATH PGP'
If rc = 0 Then
Do
If Open('ppath','PIPE:PGPPATH','R') Then
Do
path = ReadLN('ppath')
If ~Close('ppath') Then Nop
Return path
End
End
Else
Do
'GetEnv >PIPE:PGPPATH PGPPATH'
If rc = 0 Then
Do
If Open('ppath','PIPE:PGPPATH','R') Then
Do
path = ReadLN('ppath')
If ~Close('ppath') Then Nop
path = path||'/PGP'
Return path
End
Else Return ""
End
End